package edu.towson.cosc490.incaseofemergency;

import android.location.Location;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class FluOptions extends Activity {
	Button m_fluKit;
	Button m_fluMap;
	Button m_fluInformation;
	Activity FluOptionsActivity;

	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_flu_options);
		initLayout();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_flu_options, menu);
		return true;
	}
	
	public void initLayout(){
		FluOptionsActivity = this;
		final LocationManager locationManager =
		        (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
		
		m_fluKit = (Button) this.findViewById(R.id.buttonFluKit);
		m_fluKit.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				Intent openFluKitIntent = new Intent(FluOptionsActivity, SupplyKit.class);
				openFluKitIntent.putExtra("kitType", 3);
				startActivity(openFluKitIntent);
			}
		});
		
		m_fluMap = (Button) this.findViewById(R.id.buttonFluMap);
		m_fluMap.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				Log.i("debug", "OnClick activated");
				AlertDialog.Builder alert = new AlertDialog.Builder(FluOptionsActivity);

				alert.setTitle("Map Type");
				
				alert.setPositiveButton("Search for shelter", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						try {
							String address = "red+cross";
							Location myLoc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
							Intent mapIntent = new Intent(
									android.content.Intent.ACTION_VIEW, Uri
									.parse("geo:" + myLoc.getLatitude() + "," + myLoc.getLongitude() + "?q=" + address));
							startActivity(mapIntent);
							} catch (Exception e) {
							}
					  }
					});

					alert.setNegativeButton("View weather map", new DialogInterface.OnClickListener() {
					  public void onClick(DialogInterface dialog, int whichButton) {
						  Intent weatherMapIntent = new Intent(FluOptionsActivity, WeatherMap.class);
					startActivity(weatherMapIntent);
					  }
					});

					alert.show();
			}
		});
		
		m_fluInformation = (Button) this.findViewById(R.id.buttonFluInformation);
		m_fluInformation.setOnClickListener(new Button.OnClickListener(){
			public void onClick(View v){
				Intent openFluInformationIntent = new Intent(FluOptionsActivity, FluInformation.class);
				startActivity(openFluInformationIntent);
			}
		});
	}

}
